<?php
$oJobs = JobHandler::getJobs();
$oJobConfig = $oJobs[$_SESSION['iJobID']]->getConfig();
$oUsers = UserHandler::getUsers();
$iChangers = JobHandler::getUsersWithAccess('mission', 'write');
$sMissiongroups = $oJobs[$_SESSION['iJobID']]->getMissiongroups();
$sMissionStatus = MissionHandler::getStatuses();
$oFiles = JobHandler::getFiles($_SESSION['iJobID']);
?>
<div id="layer_mission_add" class="hidden" style="visibility: visible;">
<form action="index.php" method="post" name="form_mission_add">
<input type="hidden" name="sAction" value="mission-add">
<input type="hidden" name="sView" value="job-view">
<?php
if (count($iChangers) == 1) {
	print '<input type="hidden" name="iUsers[]" value="'.$iChangers[0].'">';
}
?>
<table class="boxborder" cellspacing="0">
	<tr>
		<td class="boxhandle" colspan="2"><?php print msg('New task') ?></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Task') ?>:</td>
		<td class="fieldvalue"><input type="text" name="sTodo" id="focus_mission_add" size="60"></td>
	</tr>
<?php
if (count($sMissiongroups) > 0) {
	?>
	<tr>
		<td class="fieldname"><?php print msg('Group') ?>:</td>
		<td class="fieldvalue">
			<select name="iMissiongroupID">
	<?php
	if ($oJobConfig['bAllowNogroupMissions'])
		print '<option value="0">[ '.msg('None').' ]</option>';
	foreach ($sMissiongroups as $iThisID => $sThisMissiongroup)
	{
		print '<option value="'.$iThisID.'" '.($iThisID == $_REQUEST['iMissiongroupID'] ? 'selected' : '').'>'.$sThisMissiongroup.'</option>';
	}
	?>
			</select>
		</td>
	</tr>
	<?php
}
?>
	<tr>
		<td class="fieldname"><?php print msg('Status') ?>:</td>
		<td class="fieldvalue">
			<select name="iStatus">
<?php
for ($i = 0; $i < count($sMissionStatus); $i++)
{
	print '<option class="missionstatus'.$i.'" value="'.$i.'">'.$sMissionStatus[$i]['caption'].'</option>';
}
?>
			</select>
		</td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Urgency') ?>:</td>
		<td class="fieldvalue">
			<select name="iUrgency">
<?php
for ($i = 0; $i < count($oJobs[$_SESSION['iJobID']]->sUrgencies); $i++)
{
	print '<option value="'.$i.'" '.($i == 1 ? 'selected' : '').'>'.$oJobs[$_SESSION['iJobID']]->sUrgencies[$i].'</option>';
}
?>
			</select>
		</td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Deadline') ?>:</td>
		<td class="fieldvalue">
			<?php print msg('Active') ?>:
			<input type="checkbox" name="bFinishTime" onClick="
				oForm = document.form_mission_add;
				oForm.iYear.disabled = !this.checked;
				oForm.iMonth.disabled = !this.checked;
				oForm.iDay.disabled = !this.checked;
				oForm.iHour.disabled = !this.checked;
			">
			<table cellspacing="0">
				<tr>
					<td class="fieldvalue small center"><?php print msg('Year') ?></td>
					<td class="fieldvalue small center"><?php print msg('Month') ?></td>
					<td class="fieldvalue small center"><?php print msg('Day') ?></td>
				</tr>
				<tr>
					<td class="fieldvalue small center"><input type="text" size="4" maxlength="4" name="iYear" value="<?php print date('Y') ?>" disabled></td>
					<td class="fieldvalue small center"><input type="text" size="2" maxlength="2" name="iMonth" value="<?php print date('m') ?>" disabled></td>
					<td class="fieldvalue small center"><input type="text" size="2" maxlength="2" name="iDay" value="<?php print date('d') ?>" disabled></td>
				</tr>
				<tr>
					<td class="fieldvalue small" colspan="3"><?php print msg('Time') ?>: <input type="text" size="2" maxlength="2" name="iHour" value="17" disabled>:00</td>
				</tr>
			</table>
		</td>
	</tr>
<?php
if (count($iChangers) > 1) {
	?>
	<tr>
		<td class="fieldname"><?php print msg('Assignment') ?>:</td>
		<td class="fieldvalue">
	<?php
	foreach ($iChangers as $iThisChanger)
	{
		print '<input type="checkbox" name="iUsers[]" value="'.$iThisChanger.'" '.($iThisChanger == $_SESSION['rid'] ? 'checked' : '').'>'.$oUsers[$iThisChanger]->sUser.'<br>';
	}
	?>
		</td>
	</tr>
	<?php
}
if (count($oFiles) > 0) {
	?>
	<tr>
		<td class="fieldname"><?php print msg('Files') ?>:</td>
		<td class="fieldvalue">
	<?php
	foreach ($oFiles as $oThisFile) {
		print '<input type="checkbox" name="iFiles[]" value="'.$oThisFile->iID.'">'.($oThisFile->sDescription ? $oThisFile->sDescription : $oThisFile->sFilename).'<br>';
	}
	?>
		</td>
	</tr>
	<?php
}
?>
	<tr>
		<td class="boxbody" style="text-align: center;" colspan="2">
			<input type="submit" value="<?php print msg('OK') ?>">
			<input type="button" value="<?php print msg('Cancel') ?>" onClick="layerHide('layer_mission_add');">
		</td>
	</tr>
</table>
</form>
</div>
